package cloud.maque.admin.impl;


import cloud.maque.admin.domain.entity.MqUserDepartment;
import cloud.maque.admin.mapper.MqUserDepartmentMapper;
import cloud.maque.admin.service.MqUserDepartmentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhuyf
 * @date 2023/3/2 10:02
 */
@Service
public class MqUserDepartmentServiceImpl extends ServiceImpl<MqUserDepartmentMapper, MqUserDepartment> implements MqUserDepartmentService {
    @Override
    public void AddUserDepartment(List<MqUserDepartment> userDepartments) {
        this.saveBatch(userDepartments);
    }

    @Override
    public List<MqUserDepartment> GetDepartments(String userId) {
        QueryWrapper<MqUserDepartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MqUserDepartment::getUserId, userId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Boolean deleteByUserId(String userId) {
        QueryWrapper<MqUserDepartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MqUserDepartment::getUserId, userId);
        return baseMapper.delete(queryWrapper) > 0 ? true : false;
    }
}
